#!/bin/bash

set -e

(git symbolic-ref HEAD | grep -q 'refs/heads/master') || {
  echo "Only release from the master branch."
  exit 1
}

VERSION_FILE="./lib/github-pages/version.rb"
OLD_VERSION=$(curl "https://rubygems.org/api/v1/versions/github-pages/latest.json" | jq -r .version)
NEW_VERSION=$(expr $OLD_VERSION + 1)
echo -e "# frozen_string_literal: true\n\nmodule GitHubPages\n  VERSION = $NEW_VERSION\nend" > $VERSION_FILE
git add $VERSION_FILE
git commit -m "Bump :gem: to v$NEW_VERSION"
git push origin master

script/release

echo "Ok! v$NEW_VERSION is released."
echo "Please fill out the release: https://github.com/github/pages-gem/releases/tag/v$NEW_VERSION"
echo "Here's the git history since the last release:"
git log --pretty=oneline v$OLD_VERSION...v$NEW_VERSION
